from IPython.core.interactiveshell import InteractiveShell
from IPython.core.display import HTML, display
from IPython.display import IFrame
InteractiveShell.ast_node_interactivity = 'all'
display(HTML("<style>.container { width:100% !important; }</style>"))
%config InlineBackend.figure_format = 'retina'
import os
import pandas as pd
wd = '/Users/zxs/Downloads'
os.chdir(wd)
import zipfile
fn = 'dutch-energy.zip'
stage = '/Users/zxs/data/dutch_energy'
try:
os.mkdir(stage)
except:
print('Directory exists')
z = zipfile.ZipFile(fn, 'r')
z.extractall(stage)
z.close()
os.listdir(stage)
d = {}
for folder in os.listdir(stage):
os.chdir(stage + '/' + folder)
dat = []
for file in os.listdir():
df = pd.read_csv(file)
dat.append(df)
d[folder] = dat
os.chdir(stage)
gas = pd.DataFrame()
for row in d['Gas']:
gas = gas.append(row, ignore_index = True)
gas
import geopandas as gpd
os.chdir('/Users/zxs/Downloads')
sh = gpd.read_file('Netherlands_shapefile/nl_1km.shp')
sh1 = gpd.read_file('Netherlands_shapefile/nl_10km.shp')
sh2 = gpd.read_file('Netherlands_shapefile/nl_100km.shp')
import matplotlib.pyplot as plt
%matplotlib inline
sh.plot()
sh1.plot()
sh2.plot()
os.chdir('/Users/zxs/Downloads')
buildings = gpd.read_file('netherlands-building-shape/buildings.shp')
buildings.plot()
railways = gpd.read_file('netherlands-railways-shape/railways.shp')
railways.plot()
waterways = gpd.read_file('netherlands-waterways-shape/waterways.shp')
roads = gpd.read_file('netherlands-roads-shape/roads.shp')
waterways.plot()
roads.plot()
fig, ax = plt.subplots(figsize = [25, 25])
railways.plot(ax = ax, color = 'red', linewidth = 1)
roads.plot(ax = ax, color = 'black', alpha = .5, linewidth = .2)
ax.set_axis_off()
fig.show()
fig, ax = plt.subplots(figsize = [25, 25])
railways.plot(ax = ax, color = 'red', linewidth = 1, label = 'Railways')
roads.plot(ax = ax, color = 'black', alpha = .5, linewidth = .2, label = 'Roads')
buildings.plot(ax = ax)
waterways.plot(ax = ax, color = 'blue', linewidth = 2, label = 'Water')
ax.set_axis_off()
plt.legend()
plt.set_title('Comprehensive Map of the Netherlandas', fontsize = 32)
fig.show()
fig, ax = plt.subplots(figsize = [25, 25])
railways.plot(ax = ax, color = 'red', linewidth = 1, label = 'Railways')
roads.plot(ax = ax, color = 'black', alpha = .5, linewidth = .2, label = 'Roads')
buildings.plot(ax = ax, alpha = 1)
waterways.plot(ax = ax, color = 'blue', linewidth = 2, label = 'Water', alpha = .2)
ax.set_axis_off()
plt.legend()
ax.set_title('Comprehensive Map of the Netherlandas', fontsize = 32)
fig.show()
electricity = pd.DataFrame()
for row in d['Electricity']:
electricity = electricity.append(row, ignore_index = True)
electricity.head()
buildings1 = buildings.loc[buildings['type'] != 'None']
from mpl_toolkits.basemap import Basemap
from matplotlib.patches import Polygon as PG
from matplotlib.collections import PatchCollection
from matplotlib.colors import Normalize
import geopandas as gpd
import folium
from matplotlib.patches import Patch
from shapely.geometry import Point, Polygon
import shapely.speedups
shapely.speedups.enable()
from geopandas import GeoDataFrame